CC = g++
CXXFLAGS = -pipe -Wall -Wextra -Werror -Woverloaded-virtual -pedantic -pedantic-errors -ansi --std=c++98 -g
SERVER_LFLAGS =
SERVER_TARGET = server.exe
CLIENT_LFLAGS = -lncurses
CLIENT_TARGET = client.exe
CXXFILES = server.cpp socket.cpp object.cpp player.cpp rle.cpp supergamer.cpp
HFILES  = $(CXXFILES:.cpp=.hpp) commons.hpp protocol.hpp gamer.hpp
HFILES .= medved/functor.hpp medved/scheduler.hpp medved/manager.hpp medved/util.hpp medved/typelist.hpp medved/singleton.hpp medved/shared_ptr.hpp
SRCFILES = $(CXXFILES) $(HFILES)

.PHONY: clean rebuild

all: $(SERVER_TARGET) $(CLIENT_TARGET)

clean:
	-rm *.o deps.make $(SERVER_TARGET) $(CLIENT_TARGET) med_test.exe rle_test.exe

rebuild: clean all

include deps.make

$(SERVER_TARGET): server.o socket.o player.o object.o rle.o byteorder.o
	$(CC) $^ $(CXXFLAGS) $(SERVER_LFLAGS) -o $@

$(CLIENT_TARGET): client.o socket.o supergamer.o rle.o byteorder.o player.o
	$(CC) $^ $(CXXFLAGS) $(CLIENT_LFLAGS) -o $@
	
med_test.exe: med_test.o
	$(CC) $^ $(CXXFLAGS) -o $@

rle_test.exe: rle_test.o rle.o
	$(CC) $^ $(CXXFLAGS) -o $@

.cpp.o:
	$(CC) $(CXXFLAGS) -c $<

deps.make: $(CXXFILES)
	$(CC) -MM $^ > deps.make
